#!/usr/bin/env python
# -*- coding:utf- -*-

from bottle import Bottle, request, template

from conn.MyPagerFactory import MyPager
from mail.MailLogService import MailLogService

mails = Bottle()


# ---------------------------------------------------------------------------------------------以下是计算类的定时邮件业务
# 微品GitLab提醒业务
class MailLogRoute:

    @staticmethod
    @mails.route('/', method='GET')
    def index():
        return template('emails.html', pages=MyPager.make_pager('users', [], 100, single_pager=False), errMsg='')

    @staticmethod
    @mails.post('/fetchMail')
    def fetch_mail():
        res = []
        rev_mail = request.forms.revMail
        crfrom = request.forms.crfrom
        if rev_mail is None or len(rev_mail) == 0:
            rev_mail = ''
        try:
            per_page = request.params.get("perPage")
            if per_page is None:
                per_page = 100
            res = MailLogService.fetch_log(rev_mail, crfrom)
        except Exception as e:
            print("ERROR: %s" % e)
        _pages = MyPager.make_pager('users', res['data'], per_page, single_pager=False)
        return template('emails.html', pages=_pages, errMsg='')

    @staticmethod
    @mails.route('/sendMail', method='GET')
    def send_mail() -> None:
        try:
            print("123")
        except Exception as e:
            print("ERROR: %s" % e)
